package f.f0;

import com.pgl.sys.ces.out.ISdkLite;
import f.b0;
import f.c0;
import f.q;
import f.r;
import f.z;
import g.e;
import g.g;
import g.h;
import java.io.Closeable;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.lang.reflect.Method;
import java.net.IDN;
import java.net.InetAddress;
import java.net.Socket;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

/* compiled from: Util */
public final class c {
    public static final byte[] a;
    public static final String[] b = new String[0];
    public static final c0 c;
    public static final z d;
    public static final h e = h.b("efbbbf");
    public static final h f = h.b("feff");
    public static final h g = h.b("fffe");
    public static final h h = h.b("0000ffff");
    public static final h i = h.b("ffff0000");
    public static final Charset j = Charset.forName("UTF-8");
    public static final Charset k = Charset.forName("UTF-16BE");
    public static final Charset l = Charset.forName("UTF-16LE");
    public static final Charset m = Charset.forName("UTF-32BE");
    public static final Charset n = Charset.forName("UTF-32LE");
    public static final TimeZone o = TimeZone.getTimeZone("GMT");
    public static final Comparator<String> p = new a();
    public static final Method q;
    public static final Pattern r = Pattern.compile("([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)");

    /* compiled from: Util */
    public class a implements Comparator<String> {
        public int compare(Object obj, Object obj2) {
            return ((String) obj).compareTo((String) obj2);
        }
    }

    static {
        byte[] bArr = new byte[0];
        a = bArr;
        e eVar = new e();
        eVar.z0(bArr);
        Method method = null;
        c = new b0(null, (long) bArr.length, eVar);
        d = z.create(null, bArr);
        Charset.forName("ISO-8859-1");
        try {
            method = Throwable.class.getDeclaredMethod("addSuppressed", new Class[]{Throwable.class});
        } catch (Exception unused) {
        }
        q = method;
    }

    public static AssertionError a(String str, Exception exception) {
        AssertionError assertionError = new AssertionError(str);
        try {
            assertionError.initCause(exception);
        } catch (IllegalStateException unused) {
        }
        return assertionError;
    }

    public static Charset b(g gVar, Charset charset) throws IOException {
        h hVar = e;
        if (gVar.m0(0, hVar)) {
            gVar.f((long) hVar.p());
            return j;
        }
        hVar = f;
        if (gVar.m0(0, hVar)) {
            gVar.f((long) hVar.p());
            return k;
        }
        hVar = g;
        if (gVar.m0(0, hVar)) {
            gVar.f((long) hVar.p());
            return l;
        }
        hVar = h;
        if (gVar.m0(0, hVar)) {
            gVar.f((long) hVar.p());
            return m;
        }
        hVar = i;
        if (!gVar.m0(0, hVar)) {
            return charset;
        }
        gVar.f((long) hVar.p());
        return n;
    }

    public static String c(String str) {
        int i = -1;
        int i2 = 1;
        int i3 = 0;
        if (str.contains(":")) {
            InetAddress i4;
            if (str.startsWith("[") && str.endsWith("]")) {
                i4 = i(str, 1, str.length() - 1);
            } else {
                i4 = i(str, 0, str.length());
            }
            if (i4 == null) {
                return null;
            }
            byte[] address = i4.getAddress();
            if (address.length == 16) {
                int i5 = 0;
                int i6 = 0;
                while (i5 < address.length) {
                    int i7 = i5;
                    while (i7 < 16 && address[i7] == (byte) 0 && address[i7 + 1] == (byte) 0) {
                        i7 += 2;
                    }
                    int i8 = i7 - i5;
                    if (i8 > i6 && i8 >= 4) {
                        i = i5;
                        i6 = i8;
                    }
                    i5 = i7 + 2;
                }
                e eVar = new e();
                while (i3 < address.length) {
                    if (i3 == i) {
                        eVar.B0(58);
                        i3 += i6;
                        if (i3 == 16) {
                            eVar.B0(58);
                        }
                    } else {
                        if (i3 > 0) {
                            eVar.B0(58);
                        }
                        eVar.H((long) (((address[i3] & ISdkLite.REGION_UNSET) << 8) | (address[i3 + 1] & ISdkLite.REGION_UNSET)));
                        i3 += 2;
                    }
                }
                return eVar.s0();
            }
            throw new AssertionError(c.b.a.a.a.E("Invalid IPv6 address: '", str, "'"));
        }
        try {
            str = IDN.toASCII(str).toLowerCase(Locale.US);
            if (str.isEmpty()) {
                return null;
            }
            int i9 = 0;
            while (i9 < str.length()) {
                char charAt = str.charAt(i9);
                if (charAt <= 31) {
                    break;
                } else if (charAt >= 127) {
                    break;
                } else if (" #%/:?@[\\]".indexOf(charAt) != -1) {
                    break;
                } else {
                    i9++;
                }
            }
            i2 = 0;
            if (i2 != 0) {
                return null;
            }
            return str;
        } catch (IllegalArgumentException unused) {
            return null;
        }
    }

    public static int d(String str, long j, TimeUnit timeUnit) {
        int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
        if (i >= 0) {
            Objects.requireNonNull(timeUnit, "unit == null");
            j = timeUnit.toMillis(j);
            if (j > 2147483647L) {
                throw new IllegalArgumentException(c.b.a.a.a.D(str, " too large."));
            } else if (j != 0 || i <= 0) {
                return (int) j;
            } else {
                throw new IllegalArgumentException(c.b.a.a.a.D(str, " too small."));
            }
        }
        throw new IllegalArgumentException(c.b.a.a.a.D(str, " < 0"));
    }

    public static void e(long j, long j2, long j3) {
        if ((j2 | j3) < 0 || j2 > j || j - j2 < j3) {
            throw new ArrayIndexOutOfBoundsException();
        }
    }

    public static void f(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception unused) {
            }
        }
    }

    public static void g(Socket socket) {
        if (socket != null) {
            try {
                socket.close();
            } catch (AssertionError e) {
                if (!t(e)) {
                    throw e;
                }
            } catch (RuntimeException e2) {
                throw e2;
            } catch (Exception unused) {
            }
        }
    }

    public static int h(char c) {
        if (c >= '0' && c <= '9') {
            return c - 48;
        }
        int i = 97;
        if (c < 'a' || c > 'f') {
            i = 65;
            if (c < 'A' || c > 'F') {
                return -1;
            }
        }
        return (c - i) + 10;
    }

    /* JADX WARNING: Removed duplicated region for block: B:47:0x009d  */
    /* JADX WARNING: Removed duplicated region for block: B:46:0x009c A:{RETURN} */
    @javax.annotation.Nullable
    public static java.net.InetAddress i(java.lang.String r16, int r17, int r18) {
        /*
        r0 = r16;
        r1 = r18;
        r2 = 16;
        r3 = new byte[r2];
        r4 = -1;
        r5 = 0;
        r6 = r17;
        r7 = 0;
        r8 = -1;
        r9 = -1;
    L_0x000f:
        r10 = 0;
        if (r6 >= r1) goto L_0x00d5;
    L_0x0012:
        if (r7 != r2) goto L_0x0015;
    L_0x0014:
        return r10;
    L_0x0015:
        r11 = r6 + 2;
        r12 = 4;
        r13 = 255; // 0xff float:3.57E-43 double:1.26E-321;
        if (r11 > r1) goto L_0x0032;
    L_0x001c:
        r14 = "::";
        r15 = 2;
        r14 = r0.regionMatches(r6, r14, r5, r15);
        if (r14 == 0) goto L_0x0032;
    L_0x0025:
        if (r8 == r4) goto L_0x0028;
    L_0x0027:
        return r10;
    L_0x0028:
        r7 = r7 + 2;
        r8 = r7;
        if (r11 != r1) goto L_0x002f;
    L_0x002d:
        goto L_0x00d5;
    L_0x002f:
        r9 = r11;
        goto L_0x00a2;
    L_0x0032:
        if (r7 == 0) goto L_0x00a1;
    L_0x0034:
        r11 = ":";
        r14 = 1;
        r11 = r0.regionMatches(r6, r11, r5, r14);
        if (r11 == 0) goto L_0x0041;
    L_0x003d:
        r6 = r6 + 1;
        goto L_0x00a1;
    L_0x0041:
        r11 = ".";
        r6 = r0.regionMatches(r6, r11, r5, r14);
        if (r6 == 0) goto L_0x00a0;
    L_0x0049:
        r6 = r7 + -2;
        r11 = r6;
    L_0x004c:
        if (r9 >= r1) goto L_0x0094;
    L_0x004e:
        if (r11 != r2) goto L_0x0051;
    L_0x0050:
        goto L_0x0097;
    L_0x0051:
        if (r11 == r6) goto L_0x005e;
    L_0x0053:
        r15 = r0.charAt(r9);
        r14 = 46;
        if (r15 == r14) goto L_0x005c;
    L_0x005b:
        goto L_0x0097;
    L_0x005c:
        r9 = r9 + 1;
    L_0x005e:
        r14 = r9;
        r15 = 0;
    L_0x0060:
        if (r14 >= r1) goto L_0x0082;
    L_0x0062:
        r5 = r0.charAt(r14);
        r2 = 48;
        if (r5 < r2) goto L_0x0082;
    L_0x006a:
        r4 = 57;
        if (r5 <= r4) goto L_0x006f;
    L_0x006e:
        goto L_0x0082;
    L_0x006f:
        if (r15 != 0) goto L_0x0074;
    L_0x0071:
        if (r9 == r14) goto L_0x0074;
    L_0x0073:
        goto L_0x0097;
    L_0x0074:
        r15 = r15 * 10;
        r15 = r15 + r5;
        r15 = r15 - r2;
        if (r15 <= r13) goto L_0x007b;
    L_0x007a:
        goto L_0x0097;
    L_0x007b:
        r14 = r14 + 1;
        r2 = 16;
        r4 = -1;
        r5 = 0;
        goto L_0x0060;
    L_0x0082:
        r2 = r14 - r9;
        if (r2 != 0) goto L_0x0087;
    L_0x0086:
        goto L_0x0097;
    L_0x0087:
        r2 = r11 + 1;
        r4 = (byte) r15;
        r3[r11] = r4;
        r11 = r2;
        r9 = r14;
        r2 = 16;
        r4 = -1;
        r5 = 0;
        r14 = 1;
        goto L_0x004c;
    L_0x0094:
        r6 = r6 + r12;
        if (r11 == r6) goto L_0x0099;
    L_0x0097:
        r14 = 0;
        goto L_0x009a;
    L_0x0099:
        r14 = 1;
    L_0x009a:
        if (r14 != 0) goto L_0x009d;
    L_0x009c:
        return r10;
    L_0x009d:
        r7 = r7 + 2;
        goto L_0x00d5;
    L_0x00a0:
        return r10;
    L_0x00a1:
        r9 = r6;
    L_0x00a2:
        r6 = r9;
        r2 = 0;
    L_0x00a4:
        if (r6 >= r1) goto L_0x00b8;
    L_0x00a6:
        r4 = r0.charAt(r6);
        r4 = h(r4);
        r5 = -1;
        if (r4 != r5) goto L_0x00b2;
    L_0x00b1:
        goto L_0x00b8;
    L_0x00b2:
        r2 = r2 << 4;
        r2 = r2 + r4;
        r6 = r6 + 1;
        goto L_0x00a4;
    L_0x00b8:
        r4 = r6 - r9;
        if (r4 == 0) goto L_0x00d4;
    L_0x00bc:
        if (r4 <= r12) goto L_0x00bf;
    L_0x00be:
        goto L_0x00d4;
    L_0x00bf:
        r4 = r7 + 1;
        r5 = r2 >>> 8;
        r5 = r5 & r13;
        r5 = (byte) r5;
        r3[r7] = r5;
        r7 = r4 + 1;
        r2 = r2 & 255;
        r2 = (byte) r2;
        r3[r4] = r2;
        r2 = 16;
        r4 = -1;
        r5 = 0;
        goto L_0x000f;
    L_0x00d4:
        return r10;
    L_0x00d5:
        r0 = 16;
        if (r7 == r0) goto L_0x00eb;
    L_0x00d9:
        r1 = -1;
        if (r8 != r1) goto L_0x00dd;
    L_0x00dc:
        return r10;
    L_0x00dd:
        r1 = r7 - r8;
        r2 = 16 - r1;
        java.lang.System.arraycopy(r3, r8, r3, r2, r1);
        r2 = 16 - r7;
        r2 = r2 + r8;
        r0 = 0;
        java.util.Arrays.fill(r3, r8, r2, r0);
    L_0x00eb:
        r0 = java.net.InetAddress.getByAddress(r3);	 Catch:{ UnknownHostException -> 0x00f0 }
        return r0;
    L_0x00f0:
        r0 = new java.lang.AssertionError;
        r0.<init>();
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: f.f0.c.i(java.lang.String, int, int):java.net.InetAddress");
    }

    public static int j(String str, int i, int i2, char c) {
        while (i < i2) {
            if (str.charAt(i) == c) {
                return i;
            }
            i++;
        }
        return i2;
    }

    public static int k(String str, int i, int i2, String str2) {
        while (i < i2) {
            if (str2.indexOf(str.charAt(i)) != -1) {
                return i;
            }
            i++;
        }
        return i2;
    }

    public static boolean l(g.z zVar, int i, TimeUnit timeUnit) {
        try {
            return v(zVar, i, timeUnit);
        } catch (IOException unused) {
            return false;
        }
    }

    public static boolean m(Object obj, Object obj2) {
        return obj == obj2 || (obj != null && obj.equals(obj2));
    }

    public static String n(String str, Object... objArr) {
        return String.format(Locale.US, str, objArr);
    }

    public static String o(r rVar, boolean z) {
        String d;
        String str = ":";
        if (rVar.d.contains(str)) {
            d = c.b.a.a.a.d(c.b.a.a.a.g("["), rVar.d, "]");
        } else {
            d = rVar.d;
        }
        if (!z && rVar.e == r.d(rVar.a)) {
            return d;
        }
        StringBuilder i = c.b.a.a.a.i(d, str);
        i.append(rVar.e);
        return i.toString();
    }

    public static <T> List<T> p(List<T> list) {
        return Collections.unmodifiableList(new ArrayList(list));
    }

    public static <T> List<T> q(T... tArr) {
        return Collections.unmodifiableList(Arrays.asList((Object[]) tArr.clone()));
    }

    public static int r(String str) {
        int length = str.length();
        for (int i = 0; i < length; i++) {
            char charAt = str.charAt(i);
            if (charAt <= 31 || charAt >= 127) {
                return i;
            }
        }
        return -1;
    }

    public static String[] s(Comparator<? super String> comparator, String[] strArr, String[] strArr2) {
        ArrayList arrayList = new ArrayList();
        for (Object obj : strArr) {
            for (Object compare : strArr2) {
                if (comparator.compare(obj, compare) == 0) {
                    arrayList.add(obj);
                    break;
                }
            }
        }
        return (String[]) arrayList.toArray(new String[arrayList.size()]);
    }

    public static boolean t(AssertionError assertionError) {
        return (assertionError.getCause() == null || assertionError.getMessage() == null || !assertionError.getMessage().contains("getsockname failed")) ? false : true;
    }

    public static boolean u(Comparator<String> comparator, String[] strArr, String[] strArr2) {
        if (!(strArr == null || strArr2 == null || strArr.length == 0 || strArr2.length == 0)) {
            for (Object obj : strArr) {
                for (Object compare : strArr2) {
                    if (comparator.compare(obj, compare) == 0) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public static boolean v(g.z zVar, int i, TimeUnit timeUnit) throws IOException {
        long nanoTime = System.nanoTime();
        long c = zVar.B().e() ? zVar.B().c() - nanoTime : Long.MAX_VALUE;
        zVar.B().d(Math.min(c, timeUnit.toNanos((long) i)) + nanoTime);
        try {
            e eVar = new e();
            while (zVar.c(eVar, 8192) != -1) {
                eVar.n();
            }
            if (c == Long.MAX_VALUE) {
                zVar.B().a();
            } else {
                zVar.B().d(nanoTime + c);
            }
            return true;
        } catch (InterruptedIOException unused) {
            if (c == Long.MAX_VALUE) {
                zVar.B().a();
            } else {
                zVar.B().d(nanoTime + c);
            }
            return false;
        } catch (Throwable th) {
            if (c == Long.MAX_VALUE) {
                zVar.B().a();
            } else {
                zVar.B().d(nanoTime + c);
            }
            throw th;
        }
    }

    public static int w(String str, int i, int i2) {
        while (i < i2) {
            char charAt = str.charAt(i);
            if (charAt != 9 && charAt != 10 && charAt != 12 && charAt != 13 && charAt != ' ') {
                return i;
            }
            i++;
        }
        return i2;
    }

    public static int x(String str, int i, int i2) {
        for (i2--; i2 >= i; i2--) {
            char charAt = str.charAt(i2);
            if (charAt != 9 && charAt != 10 && charAt != 12 && charAt != 13 && charAt != ' ') {
                return i2 + 1;
            }
        }
        return i;
    }

    public static q y(List<f.f0.i.c> list) {
        f.q.a aVar = new f.q.a();
        for (f.f0.i.c cVar : list) {
            a.a.a(aVar, cVar.a.w(), cVar.b.w());
        }
        return new q(aVar);
    }

    public static String z(String str, int i, int i2) {
        i = w(str, i, i2);
        return str.substring(i, x(str, i, i2));
    }
}
